rm(list = ls())



data <- read_excel("Data/2_data_final_std.xlsx")

data_europe <- data %>% 
  subset(region=="Europe" &  (polity>=6 | is.na(polity))) #Ukraine drops out


#Figure 1
data_europe$country_DB <- factor(data_europe$country_DB, levels = unique(data_europe$country_DB[order(data_europe$restrict_freedom_index)])) #sort df according corrupt_salience and fix order


plotA <- ggplot(subset(data_europe, !is.na(restrict_freedom_index)), aes(x=country_DB, y=restrict_freedom_index)) +
  geom_bar(stat="identity") + # Draw points
  theme_bw() +
  ylab("1a) Restrict freedom index") +
  xlab("") + 
  theme(axis.text=element_text(size=24),
        axis.title=element_text(size=24)) +
  coord_flip()
plotA

data_europe$country_DB <- factor(data_europe$country_DB, levels = unique(data_europe$country_DB[order(data_europe$power_concentration_index)])) #sort df according corrupt_salience and fix order


plotB <- ggplot(subset(data_europe, !is.na(power_concentration_index)), aes(x=country_DB, y=power_concentration_index)) +
  geom_bar(stat="identity") + # Draw points
  theme_bw() +
  ylab("1b) Power concentration index") +
  xlab("") + 
  theme(axis.text=element_text(size=24),
        axis.title=element_text(size=24)) +
  coord_flip()+
  scale_y_continuous(limits = c(-5, 7.5), breaks = c(-5,-2.5, 0, 2.5, 5, 7.5))
plotB


#Figure 1
if(.Platform$OS.type != "unix") windows(20,20)
ggarrange(plotA, plotB)
ggsave("Out/Figure1.jpeg", width=30, height=18, dpi=1200, device="jpeg")


#Figure 2


ggplot(data_europe, aes(x=power_concentration_index, y=restrict_freedom_index))+
  geom_point()+
  geom_smooth(method = "lm")+
  geom_text_repel(aes(label = country_DB),
                  size = 5, show.legend=FALSE)+
  xlab("Power concentration index") + 
  ylab("Restrict freedom index")+
  theme(axis.text=element_text(size=12),
        axis.title=element_text(size=18)) +
  scale_y_continuous(limits = c(-7.5, 5), breaks = c(-7.5,-5,-2.5, 0, 2.5, 5))+
  scale_x_continuous(limits = c(-5, 7.5), breaks = c(-5,-2.5, 0, 2.5, 5, 7.5))
ggsave("Out/Figure2.jpeg", width=16, height=12, dpi=1200, device="jpeg")


